<?php
/*
 * emarket - a website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This file is part of emarket.
 *
 * emarket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * emarket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with emarket.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
global $framework;
require_once("$framework/debug.php");

/**
 * Class to maintain user php session.
 * @author frederic delorme
 *
 */
class Session{
	private static $_instance;
	
	public function  __construct(){
	}

	public function start(){
		__debug(__CLASS__."::start() session started.",__FILE__,__LINE__);
		session_name("csstest");
		session_start();
	}	
	
	public function remove(){
		__debug(__CLASS__."::remove() session destroyed.",__FILE__,__LINE__);
		session_destroy();
	}
	
	public function get($key){
		__debug(__CLASS__."::get() key=$key",__FILE__,__LINE__);
		if(!empty($_SESSION[$key])){
			__debug(__CLASS__."::get() value=".print_r($_SESSION[$key],true).".",__FILE__,__LINE__);
			return $_SESSION[$key];
		}else{
			return "";
		}
	}
	/**
	 * Set an object <strong>$object</strong> into the session with identifier <strong>$key</strong. 
	 * @param $key identifier for the object in the session.
	 * @param $object object to be stored into the session.
	 * @return unknown_type
	 */
	public function set($key, $object){
		__debug(__CLASS__."::set() key='$key',".print_r($object,true),__FILE__,__LINE__);
		if($key!="" && $object!=""){
			$_SESSION[$key] = $object;
		}else{
			__error(__CLASS__."::set() key or object is null",__FILE__,__LINE__);
		}
	}	

	/**
	 * Return the singleton for Session object manager.
	 * @return unknown_type
	 */
	public function getInstance(){
		__debug(__CLASS__."::getInstance()",__FILE__,__LINE__);
		if(empty(self::$_instance)){
			self::$_instance = new Session();
			self::$_instance->start();
		}
		return self::$_instance;
	}
}
?>
